package demo1;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-05-22
 * Time: 8:04
 */
public class Main {
    static int count = 0;
    public static void printTerm(Stack<Integer> stack) {
        int flag = 0;
        for (int n :
                stack) {
            if(flag == 0) {
                System.out.print(n);
                flag = 1;
            } else {
                System.out.print("+" + n);
            }

        }
    }
    public static void dfs(int n, int curSum, int startTerm, Stack<Integer> stack) {
        if(curSum == n) {
            count++;
            if(count % 4 != 1) {
                System.out.print(";");
            }
            System.out.print(n + "=");
            printTerm(stack);

            if(count % 4 == 0) {
                System.out.println();
            }
        } else {
            for(int i = startTerm; i <= n; i++) {
                if(!stack.empty()) {
                    if(stack.peek()>i) {
                        continue;
                    }
                }
                stack.add(i);
                curSum += i;
                if(curSum <= n) {
                    dfs(n, curSum, startTerm, stack);
                    curSum -= i;
                    if(!stack.empty()) {
                        stack.pop();
                    }
                } else {
                    if(!stack.empty()) {
                        stack.pop();
                    }
                    return;
                }
            }
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Stack<Integer> stack = new Stack<>();
        Queue<Integer> queue = new LinkedList<>();

        int n = scanner.nextInt();
        dfs(n, 0, 1, stack);
        scanner.close();
    }
    public static void main5(String[] args) {
        Scanner in = new Scanner(System.in);
        Set<Integer> set = new HashSet<>();
        while (in.hasNextInt()) {
            int n = in.nextInt();
            if(set.contains(n)) {
                System.out.println("yes");
                return;
            }
            set.add(n);
        }
        System.out.println("no");
    }


    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] chars = {'A', 'B', 'C', 'D', 'E'};
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int bot = scanner.nextInt();
            chars = func(bot, chars);
        }
        System.out.print(chars[0]);
        for (int i = 1; i < 5; i++) {
            System.out.print("," + chars[i]);
        }
    }

    private static char[] func(int bot, char[] chars) {
        if (bot == 1) {
            char c = chars[0];
            chars = Arrays.copyOfRange(chars, 1, 5);
            chars = Arrays.copyOf(chars, 5);
            chars[4] = c;
        } else if (bot == 2) {
            char[] chars1 = new char[5];
            chars1[0] = chars[4];
            int k = 0;
            for (int i = 0; i < 4; i++) {
                chars1[++k] = chars[i];
            }
            chars = chars1;
        } else {
            char c = chars[0];
            chars[0] = chars[1];
            chars[1] = c;
        }
        return chars;
    }

    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        int count = scanner.nextInt();
        for (int i = 0; i < count; i++) {
            int index = scanner.nextInt() - 1;
            nums[index] = Integer.MAX_VALUE;
            for (int j = index; j < n - 1; j++) {
                nums[j] = nums[j + 1];
            }
            n--;
        }
        int flag = 0;
        for (int i = 0; i < n; i++) {
            if(flag == 0) {
                System.out.print(nums[i]);
                flag = 1;
            } else {
                System.out.print(" " + nums[i]);
            }

        }
    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int[] numa = new int[a];
        for (int i = 0; i < a; i++) {
            numa[i] = scanner.nextInt();
        }
        int b = scanner.nextInt();
        int[] numb = new int[b];
        for (int i = 0; i < b; i++) {
            numb[i] = scanner.nextInt();
        }
        Arrays.sort(numa);
        Arrays.sort(numb);
        int k = 0;
        int ka = 0;
        int kb = 0;
        while (k < 3) {
            if(numa[a - 1] > numb[b - 1]) {
                a--;
                if (k == 0) {
                    System.out.print(numa[a]);
                } else {
                    System.out.print(" " + numa[a]);
                }
                ka++;
            } else {
                b--;
                if (k == 0) {
                    System.out.print(numb[b]);
                } else {
                    System.out.print(" " + numb[b]);
                }
                kb++;
            }
            k++;
        }
        if(ka>kb) {
            System.out.println();
            System.out.println("A");
        } else {
            System.out.println();
            System.out.println("B");
        }
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nums = new int[0];
        int k = 0;
        for (int i = 0; i < 3; i++) {
            int n = scanner.nextInt();
            nums = Arrays.copyOf(nums, nums.length + n);
            for (int j = 0; j < n; j++) {
                nums[k++] = scanner.nextInt();
            }
        }
        for (int i = 0; i < k - 1; i++) {
            for (int j = 0; j < k - 1 - i; j++) {
                if(nums[j] < nums[j + 1]) {
                    int t = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = t;
                }
            }
        }
        for (int i = 0; i < k; i++) {
            if(i == 0) {
                System.out.print(nums[i]);
            } else {
                System.out.print(" " + nums[i]);
            }
        }
    }
}
